﻿
function isMobileBrowser()
{
	return /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) == true;
}

function redirect(url)
{
	window.top.location = url;
}

function getSafeElementID(elementID)
{
	if (elementID.lastIndexOf("#", 0) == 0)
	{
		return elementID;
	}
	else
	{
		return "#" + elementID;
	}
}

/* Collapse Threads */
function collapseThread(childrenID, collapseButtonID, expandButtonID)
{
	$(getSafeElementID(childrenID)).hide();
	$(getSafeElementID(collapseButtonID)).hide();
	$(getSafeElementID(expandButtonID)).show();
}

function expandThread(childrenID, collapseButtonID, expandButtonID)
{
	$(getSafeElementID(childrenID)).show();
	$(getSafeElementID(collapseButtonID)).show();
	$(getSafeElementID(expandButtonID)).hide();
}


function showAjaxException(jqXHR, textStatus, errorThrown)
{
	// should we be logging this?	
	var newDialog = $(document.createElement("div"));
	newDialog.html(jqXHR.responseText);

	// just in case
	unblockUI();

	newDialog.dialog(
	{
		title: "Exception results from ajax call",
		autoOpen: true,
		modal: true,
		dialogClass: "modal-dialog",
		height: $(window).height() * 0.9,
		width: $(window).width() * 0.9,
		open: function ()
		{
			$(".ui-dialog-titlebar-close").show();
		},
		close: function ()
		{
			newDialog.dialog("destroy");
			newDialog.remove();
		}
	});
}

$(function ()
{
	// add max length attributes for textboxes with maxlength validation attached
	$("input[data-val-length-max]").each(function ()
	{
		var $this = $(this);
		var data = $this.data();
		$this.attr("maxlength", data.valLengthMax);
	});
});